<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Person extends Model
{
  /**
   * Insert validation rules.
   *
   * @var array
   */
  public static $insertRules = [
    'user_id' => 'required|int|unique:people',
    'name' => 'required|max:255',
    'surname' => 'required|max:255',
    'sex' => 'required|in:F,M',
    'birthdate' => 'required|date',
    'birthplace' => 'required|max:255',
    'fiscalcode' => 'required|max:255',
    'active' => 'nullable|boolean',
  ];

  /**
   * Update validation rules.
   *
   * @var array
   */
  public static $updatetRules = [
    'user_id' => 'nullable|int|unique:people',
    'name' => 'nullable|max:255',
    'surname' => 'nullable|max:255',
    'sex' => 'nullable|in:F,M',
    'birthdate' => 'nullable|date',
    'birthplace' => 'nullable|max:255',
    'fiscalcode' => 'nullable|max:255',
    'active' => 'nullable|boolean',
  ];
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable = [
    'user_id',
    'name',
    'surname',
    'sex',
    'birthdate',
    'birthplace',
    'fiscalcode',
    'active',
  ];

  /**
   * The attributes excluded from the model's JSON form.
   *
   * @var array
   */
  protected $hidden = [
    'user_id',
  ];

  /**
   * The attributes that should be cast to native types.
   *
   * @var array
   */
  protected $casts = [
    'birthdate' => 'datetime',
  ];

  /**
   * Relationship with user.
   */
  public function user()
  {
    return $this->belongsTo(User::class);
  }
}
